package exercise;

import bean.ExamStudent;
import org.junit.Test;
import preparedStatement.PreparedStatementQueryTest;
import preparedStatement.PreparedStatementUpdateTest;

import java.util.List;

//课后练习2
public class Exercise2MyTest {

    //代码实现1：向examstudent表中插入一个新的student信息
    @Test
    public void insertTest() {
        PreparedStatementUpdateTest pt = new PreparedStatementUpdateTest();
        String sql = "insert into examstudent(type,IDCard,ExamCard,StudentName,Location,Grade)" +
                "values(?,?,?,?,?,?)";
        //调用通用的增删改方法
        pt.change(sql,"4","360502200009276037","200523164754006","大神","天空岛","100");
        System.out.println("插入成功");
    }

    //代码实现2：输入身份证号或准考证号可以查询到学生的基本信息
    @Test
    public void QueryTest() {
        PreparedStatementQueryTest pq = new PreparedStatementQueryTest();
        String sql = "select " +
                "FlowID flowId,Type type,IDCard idCard,ExamCard examCard,StudentName studentName,Location location,Grade grade  " +
                "from examstudent where IDCard = ? or ExamCard = ?";
        //调用通用的查询方法，获取表的多条数据
        List<ExamStudent> examStudents = pq.getForList(ExamStudent.class, sql, "360502200009276037", "200523164754005");
        examStudents.forEach(System.out::println);
    }

    //代码实现3：完成学生信息的删除功能
    @Test
    public void deleteTest() {
        PreparedStatementUpdateTest pt = new PreparedStatementUpdateTest();
        String sql = "delete from examstudent where ExamCard = ?";
        //调用通用的增删改方法
        pt.change(sql,"200523164754006");
        System.out.println("删除成功");
    }
}
